<?php



if((strlen($_POST['password1']))>0 && (strlen($_POST['password2']))>0 && strcmp($_POST['password1'],$_POST['password2'])==0)
{
	if(strlen($_POST['zipCode'])==5 && $_POST['zipCode']==strval(intval($_POST['zipCode'])) && $_POST['zipCode']>00000 && $_POST['zipCode']<99999)
	{
	if(strlen($_POST['cellNumber'])==10 && $_POST['cellNumber']==strval(intval($_POST['cellNumber'])))
	{
	if(preg_match("/^[a-zA-Z]{2,3}[0-9]{4}$/",$_POST['CUID']) && (strlen($_POST['CUID'])==6 || strlen($_POST['CUID'])==7))
	{
		if(!(strlen($_POST['firstName'])) && !(strlen($_POST['lastName'])) && !(strlen($_POST['address1'])) && !(strlen($_POST['city'])) && !(strlen($_POST['state'])) && !(strlen($_POST['country'])) && !(strlen($_POST['zipCode'])) && !(strlen($_POST['departmentName'])))
		{
		print('Please fill the name and contact details properly');
		}
		else
		{
		echo 'Hello, ' .$_POST['firstName']. '!';
		$conn = oci_connect("gaurav", "gaurav", "xe"); 
		
		$cuid=$_POST['CUID'];
		$password=$_POST['password'];
		$firstname=$_POST['firstName'];
		$middlename=$_POST['middleName'];
		$lastname=$_POST['lastName'];
		$address1=$_POST['address1'];
		$address2=$_POST['address2'];
		$city=$_POST['city'];
		$state=$_POST['state'];
		$country=$_POST['country'];
		$zipcode=$_POST['zipCode'];
		$cellnumber=$_POST['cellNumber'];
		$sex=$_POST['sex'];
		$deptid=$_POST['departmentName'];
		$role="Administrator";		
		
		$conn = oci_connect("gaurav", "gaurav", "xe"); 
		//$stmt = oci_parse($conn, "INSERT INTO Candidate (cuid,password,fname,mname,lname,address1,address2,city,state,country,zipcode,cellnumber,creationdate,sex,deptid,role) VALUES('$cuid','$password','$firstname','$middlename','$lastname','$address1','$address2','$city','$state','$country','$zipcode','$cellnumber',SysDate,'$sex','$deptid','$role')");
		//$stmt = oci_parse($conn, "select * from Candidate where cuid like '$username' and password like '$password'"); 
		//$stmt = oci_parse($conn, "insert into Messages values(msgseq.NEXTVAL,'Hellooo000','agr2624','ax2624')");
 
		$statement =
    "INSERT INTO Messages(MessageID,Mesg,FromCUID,ToCUID) VALUES(msgseq.NEXTVAL,:mesg,:fromcuid,:tocuid)";
$fromcuid="xw2174";
$tocuid="gip2103";
$mesg="hi gp";

  $bindargs = array();
  array_push($bindargs, array('mesg', $mesg, -1));
  array_push($bindargs, array('fromcuid', $fromcuid, -1));
  array_push($bindargs, array('tocuid', $tocuid, -1));


  $r = db_execute_statement($conn, $statement, $bindargs);
//oci_execute($stmt, OCI_DEFAULT); 
		
		//$result = ora_exec($statement);
		 
  /*$statement =
  "INSERT INTO Candidate (cuid,password,fname,mname,lname,address1,address2,city,state,country,zipcode,cellnumber,creationdate,sex,deptid,role) VALUES(:cuid,:password,:firstname,:middlename,:lastname,:address1,:address2,:city,:state,:country,:zipcode,:cellnumber,SYSDATE,:sex,:deptid,:role)";*/
  /*$newemp=$_POST;
  $bindargs = array();
  array_push($bindargs, array('cuid',$newemp['cuid'], -1));
  array_push($bindargs, array('password', $newemp['password'], -1));
  array_push($bindargs, array('firstname', $newemp['firstname'], -1));
  array_push($bindargs, array('middlename', $newemp['middlename'], -1));
  array_push($bindargs, array('lastname', $newemp['lastname'], -1));
  array_push($bindargs, array('address1', $newemp['address1'], -1));
  array_push($bindargs, array('address2', $newemp['adddress2'], -1));
  array_push($bindargs, array('city', $newemp['city'], -1));
  array_push($bindargs, array('state', $newemp['state'], -1));
  array_push($bindargs, array('country', $newemp['country'], -1));
  array_push($bindargs, array('zipcode', $newemp['zipcode'], -1));
  array_push($bindargs, array('cellnumber', $newemp['cellnumber'], -1));
  array_push($bindargs, array('sex', $newemp['sex'], -1));
  array_push($bindargs, array('deptid', $newemp['deptid'], -1));
  array_push($bindargs, array('role', $newemp['role'], -1));*/
  //$r = db_execute_statement($conn, $statement, $bindargs);
		}
	}
	else
	{
		print('Enter CUID properly');
		}
		}
		else
		{
		print('Please fill the CellNumber properly');
		}
	}
	else
	{
	print('Enter 5 digit US ZipCode properly. Press back button on browser!');
	}
}
else
{
print('Enter passwords properly. Press BACK button on browser!');
}
?>